/*
 * @Author: yusha
 * @Date: 2023-07-27 17:28:40
 * @LastEditors: yusha
 * @LastEditTime: 2023-08-25 13:51:23
 * @Description:
 */
import axios from 'axios';
import { debounce } from 'lodash';


export const validateCodeVersion = () => {
    const axiosV = axios.create({
        timeout: 3 * 60 * 1000,
        baseURL: '',
    });
    debounce(() => {
        const curVersion = window.curVersion ?? {};
        if (curVersion.time + (10 * 60 * 1000) < Date.now()) {
            //
        } else {
            // 1:client 2:system 3:wms
            axiosV.post('/customer/getClientVersion', { project: 2 }).then(res => {
                // console.log(res);
                if (!curVersion.version) {
                    //
                } else if (curVersion.version !== res?.data?.data) {
                    requestAnimationFrame(() => {
                        window.location.reload();
                    });
                }
                curVersion.version = res?.data?.data;
                curVersion.time = Date.now();
                window.curVersion = curVersion;
            });
        }
    }, 1000);
};
